import { renderIcon } from "../utils/CommonUtils";
import { type RemoveMethods } from "@/types/remove-methods";
import { Book } from "@vicons/ionicons5";

export class TaskBoardData {
  name: string;
  chooseFields: Array<number>;
  menuOption: string;
  radioOption: string;
  key: number;

  constructor(name: string, chooseFields: Array<number>) {
    this.name = name;
    this.chooseFields = chooseFields;
    this.key = 0;
    this.radioOption = "表格";
  }

  static getOptions() {
    return ["需处理", "过期", "未提醒", "未指定日期", "未开始", "已结束"].map(s => {
      return { key: s, label: s, icon: renderIcon(Book) };
    });
  }
  static getOptionKey(str: string) {
    if (str === "需处理" || str === "过期" || str === "未指定日期" || str === "未提醒") return "onGonging";
    if (str === "未开始") return "stopping";
    if (str === "已结束") return "finished";
    return "";
  }
}

export class TaskBoardList {
  taskBoardList: Array<TaskBoardData>;
  changeKey: number;

  recordTaskId: number;
  recordBeginTime: number;
  recordType: number; // 1普通(临时可以建立领域处理)，2生活模式
  recordFlag: boolean; // true代表正在计时

  key: number;

  static beginRecord(taskBoardList: TaskBoardList, recordTaskId: number, recordType: number) {
    if (!taskBoardList.recordFlag) {
      taskBoardList.recordTaskId = recordTaskId;
      taskBoardList.recordBeginTime = new Date().getTime();
      taskBoardList.recordType = recordType;
      taskBoardList.recordFlag = true;
      return true;
    } else return false;
  }
  static endRecord(taskBoardList: TaskBoardList) {
    if (taskBoardList.recordFlag) {
      taskBoardList.recordFlag = false;
      return true;
    } else return false;
  }

  setInfo(data: RemoveMethods<TaskBoardList>) {
    Object.assign(this, data);
  }

  constructor(taskBoardList: Array<TaskBoardData>) {
    this.taskBoardList = taskBoardList;
    this.key = 0;
  }

  static addTaskBoardData(taskBoardList: TaskBoardList, taskBoardData: TaskBoardData) {
    taskBoardList.taskBoardList.push(taskBoardData);
  }
}
